<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>设置</title>
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />

    <style>
        * {
            background: #f2f2f1;
        }

        .fff {
            height: 18px;
        }

        .repair-possword {
            border-bottom: 3px solid #ecebeb;
            line-height: 43px;
            color: #727272;
            background: #fff;
            padding-left: 24px;
            padding-right: 28px;
        }

        .setupright {
            float: right;
            background: #fff;
        }

        .jiantou {
            width: 10px;
            height: 18px;
            vertical-align: middle;
            display: inline;
            background: #fff;
        }

        .off {
            position: fixed;
            line-height: 43px;
            background: #fff;
            line-height: 43px;
            text-align: center;
            font-size: 17px;
            color: #727272;
            left: 0px;
            bottom: 0px;
            right: 0px;
            /*padding-bottom: 25px;*/
        }

        .slid {
            position: absolute;
            right: 27px;
            height: 19px;
            width: 48px;
            bottom: 12px;
            background-color: rgba(0, 0, 0, 0);
        }

        .aui-switch:checked {
            border-color: #ea5718;
            background-color: #ea5718;
        }

        .hide {
            display: none !important;
        }

        .mask {
            position: fixed;
            left: 0px;
            top: 0px;
            right: 0px;
            bottom: 0px;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 5;
        }

        .mask .bombbox {
            position: fixed;
            left: 45px;
            right: 45px;
            top: 50%;
            background-color: #fff;
            text-align: center;
            margin-top: -25%;
        }

        .bombbox-title {
            line-height: 3rem;
            font-size: 17px;
            color: #1a1a1a;
            font-weight: bold;
        }

        .bombbox-content {
            font-size: 0.7rem;
            text-align: left;
            padding-left: 0.8rem;
            padding-right: 0.8rem;
            line-height: 1rem;
            color: #1a1a1a;
            margin-bottom: 15px;
        }

        .bombbox-foot {
            line-height: 2.2rem;
            border-top: 1px solid #d9d9d9;
            position: relative;
        }

        .segmenting {
            position: absolute;
            width: 1px;
            height: 34px;
            background: url(../../image/split.png) no-repeat;
            left: 50%;
            top: 5px;
        }
    </style>
</head>

<body>
    <div id="vm" v-cloak>
        <div class="big-box">

            <div class="fff"></div>
            <div class="repair-possword" onclick="ModifyPhoneWin()" v-if="isloginflag">
                  修改手机
                  <div class="setupright">
                      <img src="../../image/login/jiantou.png" alt="" class="jiantou">
                  </div>
                  <div class="aui-clearfix"></div>
              </div>
              <div class="repair-possword" onclick="loginwin()" v-else>
                  修改手机
                  <div class="setupright">
                      <img src="../../image/login/jiantou.png" alt="" class="jiantou">
                  </div>
                  <div class="aui-clearfix"></div>
              </div>

              <div class="repair-possword" onclick="ModifyPasswordWin()" v-if="isloginflag">
                  修改密码
                  <div class="setupright">
                      <img src="../../image/login/jiantou.png" alt="" class="jiantou">
                  </div>
              </div>
              <div class="repair-possword" onclick="loginwin()" v-else>
                  修改密码
                  <div class="setupright">
                      <img src="../../image/login/jiantou.png" alt="" class="jiantou">
                  </div>
              </div>
            <div class="repair-possword" v-if='system'>
                消息推送开关
                <div class="setupright">
                    <input type="checkbox" class="aui-switch" style="display:inline-block;vertical-align:middle;" v-model="tuisong">
                </div>
                <div class="aui-clearfix"></div>
            </div>
            <div class="repair-possword" v-else>
                消息推送开关
                <div class="setupright">
                    <input type="checkbox" class="aui-switch" style="display:inline-block;vertical-align:middle;" v-model="tuisong2">
                </div>
                <div class="aui-clearfix"></div>
            </div>
            <div class="repair-possword" v-on:click="clearcache()">
                清除缓存
                <div class="setupright">
                    {{cachenum}}MB
                </div>
            </div>
            <div class="repair-possword"  v-on:click="getversion()">
                检查更新
                <div class="setupright" v-if="newversionnum">
                    {{newversionnum}}版
                </div>

            </div>
            <div class="repair-possword" onclick="getAboutusWin()">
                关于我们
                <div class="setupright">
                    <img src="../../image/login/jiantou.png" alt="" class="jiantou">
                </div>
            </div>
            <div class="off" id="off" onclick="panduan()" v-show="isloginflag">
                 退出登录
             </div>
            <div class="mask mask3 hide">
                <div class="bombbox">
                    <div class="bombbox-title">检查更新</div>
                    <div class="bombbox-content versionnum" style="text-align:center;">{{newversionnum}}</div>
                    <div class="aui-row bombbox-foot">
                        <div class="segmenting"></div>
                        <div class="aui-col-xs-6 aui-font-size-15 cancel">以后再说</div>
                        <div class="aui-col-xs-6 aui-font-size-15 sure" v-on:click="downloadapp()">马上去</div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.2.5.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/rest.js"></script>
<script type="text/javascript" src="../../script/login.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/faskclick.js"></script>
<script type="text/javascript">
var uid=$api.getStorage('uid');
    var vm = new Vue({
        el: '#vm',
        data: {
            cachenum:'0',
            system:false,
            newversionnum: '',
            isnewversion: false,
            downloadapphref:'',
            tuisong:false,
            tuisong2:false,
            isloginflag: false
        },
        created: function() {
            var _this = this;
            apiready = function() {
                _this.init();
                api.parseTapmode();
                // alert(api.safeArea.bottom)
                $api.fixTabBar($api.byId('off'))
                var header = $api.byId('aui-header');
                $api.fixStatusBar(header);
                if ('addEventListener' in document) {
                    document.addEventListener('DOMContentLoaded', function() {
                        FastClick.attach(document.body);
                    }, false);
                }
                api.getCacheSize(function(ret) {
                    _this.cachenum = parseInt(ret.size / 1024 / 1024);
                });

                var systemType = api.systemType;
                if (systemType=='ios') {
                  _this.system = true
                  _this.setpush()
                }else {
                  var ajpush = api.require('ajpush');
                  ajpush.isPushStopped(function(ret) {
                    //1是停止了 0是接收判断的是否停止。
                    // alert(JSON.stringify(ret))
                      if(ret && ret.isStopped){
                          _this.tuisong2=false
                      }else {
                          _this.tuisong2=true
                      }
                    _this.unwatchtuisong2 = _this.$watch('tuisong2', _this.tuisongfnc2)
                  });
                }
                api.addEventListener({
                    name:'resume'
                }, function(ret, err){
                  if (_this.unwatchtuisong) {_this.unwatchtuisong()}
                    _this.setpush()
                });
            }
        },
        methods: {
            init: function() {
                var _this = this;
                if(uid){
                 _this.isloginflag=true;
               }else{
                 _this.isloginflag=false;
               }
            },
            getversion: function() {
                var _this = this;
                var mam = api.require('mam');
                mam.checkUpdate(function(ret, err) {
                  // alert(JSON.stringify(ret))
                    if (ret.status) {
                        if (ret.result.update) {
                            _this.isnewversion = true;
                            _this.newversionnum = '发现新版本' + ret.result.version;
                            _this.downloadapphref=ret.result.source
                            _this.mask3show()
                        } else {
                            _this.newversionnum = ''
                            _this.isnewversion = false;
                            api.toast({
                                msg: '已是最新版本',
                                duration: 2000,
                                location: 'middle'
                            });

                        }
                    } else {
                        api.toast({
                            msg: err.msg,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                });

            },
            mask3show: function() {
                var _this = this;
                if (_this.isnewversion) {
                    $('.mask3').removeClass('hide');
                }
            },
            downloadapp(){
              var _this=this;
              window.location.href=_this.downloadapphref;
            },
            clearcache: function() {
                var _this = this;
                api.clearCache(function() {
                    api.toast({
                        msg: '清除完成',
                        duration: 2000,
                        location: 'middle'
                    });
                });
                _this.cachenum = '0'
            },
            cache: function() {
                var _this = this;
                if (_this.cachenum == 0) {
                    $('.mask2').removeClass('hide');
                } else {
                    $('.mask6').removeClass('hide');
                }
            },
            setpush:function() {
              var _this =this;
              var judgeNotification = api.require('judgeNotification');
              judgeNotification.judge(function(ret) {
                  if (ret.status) {
                    _this.tuisong=true
                  } else {
                    _this.tuisong=false
                  }
                  _this.unwatchtuisong = _this.$watch('tuisong', _this.tuisongfnc)

              });
            },
            tuisongfnc:function(ret) {
              var setJumpNew = api.require('setJumpNew');
                  setJumpNew.open();
            },
            tuisongfnc2:function(ret) {
                var _this =this;
              var ajpush = api.require('ajpush');
              if (_this.tuisong2==true) {
                ajpush.resumePush(function(ret) {
                  if(ret && ret.status){
                    // alert('恢复推送')
                    api.toast({
                        msg: '已接收推送',
                        duration: 2000,
                        location: 'bottom'
                    });
                  }
                });
              }else {
                ajpush.stopPush(function(ret) {
                    if(ret && ret.status){
                      api.toast({
                          msg: '已停止接收推送',
                          duration: 2000,
                          location: 'bottom'
                      });
                    }
                });
              }
            },
        }
    })

    function logoff() {
        $api.rmStorage('uid');
        $api.rmStorage('session');
        $api.rmStorage('mobile');
        api.sendEvent({
            name: 'exitlogin'
        });
        api.closeWin();
    }
    function ModifyPhoneWin() {
      new rest().get('getUserInfo').datae({
          uid: uid
      }).success(function(res) {
          if (res.flag == 1) {
              if(res.msg[0].mobile){
                // _this.phonevalue =res.msg[0].mobile
                // var str =res.msg[0].mobile;
                // str.substr(str.length-11)
                api.openWin({
                    name: 'verify1',
                    url: './verify1.html',
                    pageParam:{
                      phonevalue:res.msg[0].mobile
                    }
                });
              }
          } else {
              api.toast({
                  msg: '该账号未绑定手机号',
                  duration: 2000,
                  location: 'middle'
              });
          }
          console.log(JSON.stringify(res))
      }).error(function(err) {
          console.log(JSON.stringify(err))
      }).run()

    }

    function getAboutusWin() {
        api.openWin({
            name: 'about_win',
            url: './about_win.html',
        });
    }

    function ModifyPasswordWin() {
        api.openWin({
            name: 'verifyrepair',
            url: './verify-repair.html',
        });
    }
    function loginwin() {
          api.openFrame({
              name: 'login_introduction',
              url: '../myself/login_introduction.html',
              rect: {
                  x: 0,
                  y: 0,
                  w: 'auto',
                  h: 'auto'
              },
              bounces: false,
              bgColor: 'rgba(0,0,0,0.7)',
              vScrollBarEnabled: true,
              hScrollBarEnabled: true
          });
      }
      function panduan(){
        api.openFrame({
            name: 'panduan',
            url: './panduan.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0.7)',
            vScrollBarEnabled: true,
            hScrollBarEnabled: true
        });
      }
</script>

</html>
